<?php
namespace Admin\Controller;

use Utuo\BackgroundController;

/**
 * wmfl.cn version 5.0
 * -----------------------------------------------
 *
 * @author esinger <esinger@qq.com>
 * @link http://www.utuo88.com
 * @copyright 2014 Utuo Tech co.,Ltd
 */

/**
 * 客户财务数据管理
 */
class CustomerFinanceController extends BackgroundController
{
    
    // 初始化
    public function _initialize()
    {
        $this->setControllerTitle('财务管理');
        $this->setActionTitle(array(
            'index' => '充值记录',
            'config'=>'财务配置'
        ));
        $this->setActionNav(array(
            'index',
            'config'
        ));
    }
    
    // 菜单列表
    public function indexAction()
    {
        $page = $this->getPage();
        $pagesize = $this->getPageSize();
        $m = M('CustomerFinance f');
        $m->join("LEFT JOIN __ADMIN__ a ON f.admin_id=a.id");
        $m->join("LEFT JOIN __CUSTOMER__ c ON f.cid=c.id");
        $m->field("f.*,a.name AS admin_name,c.name AS customer_name");
        $c = clone $m;
        $count = $c->count();
        $m->limit($pagesize)->page($page)->order("id DESC");
        $lists = $m->select();
        $this->showPage($count, $pagesize);
        $this->assign('lists', $lists);
        $this->display();
    }
    
    // 菜单列表
    public function configAction()
    {
        $config = M('config')->find();
        $this->assign('config', $config);
        $this->display();
    }
    
    // 保存数据
    public function saveConfigAction()
    {
        $m = M('Config');
        if ($m->create()) {
            if ($m->where('1')->save() !== false) {
                $this->ajaxSuccess('保存成功');
            } else {
                $this->ajaxError('保存失败');
            }
        } else {
            $this->ajaxError('创建数据失败');
        }
    }
}
 
// End of file MenuController.class.php
